

const path = require('path');
const staticImg = path.join(__dirname, 'static');

function ArduinoUnoBlocks(Blockly) {
    var base_color = "#179b73";



    //摇杆模块初始化端口
    Blockly.Blocks.microbit_rockInit = {
        init:function(){
        this.setColour(base_color);
        this.appendDummyInput("")
         .appendField(new Blockly.FieldImage(staticImg+"/31.Rocker - Module.svg", 84, 42))
           .appendField(Blockly.Msg.MICROBIT_ROCK)
           .appendField(Blockly.Msg.MICROBIT_ROCKXAXIS)
           .appendField(new Blockly.FieldDropdown([
            ['P0', "pin0"],
            ['P13', "pin13"],
           ]),"rockX")
           .appendField(Blockly.Msg.MICROBIT_ROCKYAXIS)
           .appendField(new Blockly.FieldDropdown([
            ['P1', "pin1"],
            ['P2', "pin2"],
           ]),"rockY")
           .appendField(Blockly.Msg.MICROBIT_ROCKBUTTON)
           .appendField(new Blockly.FieldDropdown([
            ['P8', "pin8"],
            ['P15', "pin15"],
           ]),"rockB")
           this.setPreviousStatement(true, null);
           this.setNextStatement(true, null);
           this.setTooltip('');
        }
    };
    // 获取摇杆
  Blockly.Blocks.microbit_rockData = {
    init:function(){
      this.setColour(base_color);
      this.appendDummyInput("")
      .appendField(new Blockly.FieldImage(staticImg+"/31.Rocker - Module.svg", 84, 42))
          .appendField(Blockly.Msg.MICROBIT_PIN)
          .appendField(new Blockly.FieldDropdown([
            ['P8', "pin8"],
            ['P15', "pin15"],
           ]),"rockB")
           .appendField(Blockly.Msg.MICROBIT_READROCKDATA)
          this.setOutputShape(Blockly.OUTPUT_SHAPE_HEXAGONAL);
          this.setOutput(true, 'Boolean');
          this.setTooltip('');
    }
  };

  // 获取摇杆值
  Blockly.Blocks.microbit_rock = {
    init:function(){
      this.setColour(base_color);
      this.appendDummyInput("")
      .appendField(new Blockly.FieldImage(staticImg+"/31.Rocker - Module.svg", 84, 42))
        .appendField(Blockly.Msg.MICROBIT_PIN)
        .appendField(new Blockly.FieldDropdown([
            ['P0', "pin0"],
            ['P13', "pin13"],
           ]),"rockX")
           .appendField(Blockly.Msg.MICROBIT_PIN)
           .appendField(new Blockly.FieldDropdown([
            ['P1', "pin1"],
            ['P2', "pin2"],
           ]),"rockY")
          .appendField(Blockly.Msg.MICROBIT_READROCK)
          .appendField(new Blockly.FieldDropdown([
            [Blockly.Msg.MICROBIT_ROCKXAXIS, "x"],
            [Blockly.Msg.MICROBIT_ROCKYAXIS, "y"],
          ]),"rock2")
          .appendField(Blockly.Msg.MICROBIT_ROCKVALUE)
        this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
        this.setOutput(true, 'Number');
        this.setTooltip('');
    }
  };

    return Blockly;
}

module.exports = ArduinoUnoBlocks;

